/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package ships.core;

import ships.core.models.MemoryModel;
import ships.core.exceptions.EmptyArrayException;

/**
 *
 * @author fqhuy
 */
public abstract class AbstractDataBuffer<E extends Number> {

    protected int banks;
    protected int offset;
    protected int size;
    protected int[] offsets;
    protected MemoryModel memoryModel;
    protected Class<?> cls;
    protected AbstractDataBuffer() {
    }

    protected AbstractDataBuffer(Class<?> cls) {
        this.cls = cls;
    }

    protected AbstractDataBuffer(int size, Class<?> cls) {
        this(size,1,0,cls);
    }

    protected AbstractDataBuffer(int size, int numBanks,Class<?> cls) {
        this(size, numBanks, 0,cls);
    }

    protected AbstractDataBuffer(int size, int numBanks, int offset,Class<?> cls) {
        this.banks = numBanks;
        this.size = size;
        this.offset = offset;
        this.offsets = new int[banks];
    }

    protected AbstractDataBuffer(int size, int numBanks, int[] offsets, Class<?> cls) {
        
        this.banks = numBanks;
        this.size = size;
        this.offset = offsets[0];
        this.offsets = (int[]) offsets.clone();
    }

    protected AbstractDataBuffer(int size, int numBanks, int offset, MemoryModel memoryModel,Class<?> cls) {
        this(size, numBanks, offset,cls);
        this.memoryModel = memoryModel;
    }

    protected AbstractDataBuffer(int size, int numBanks, int[] offsets, MemoryModel memoryModel,Class<?> cls) {
        this(size, numBanks, offsets,cls);
        this.memoryModel = memoryModel;
    }

    public abstract E getElem(int i);

    public abstract E getElem(int bank, int i);

    public abstract void setElem(int i, E val);

    public abstract void setElem(int bank, int i, E val);

    public int getBanks() {
        return banks;
    }

    /**
     * @param banks the banks to set
     */
    public void setBanks(int banks) {
        this.banks = banks;
    }

    /**
     * @return the offset
     */
    public int getOffset() {
        return offset;
    }

    /**
     * @param offset the offset to set
     */
    public void setOffset(int offset) {
        this.offset = offset;
    }

    /**
     * @return the size
     */
    public int getSize() {
        return size;
    }

    /**
     * @param size the size to set
     */
    public void setSize(int size) {
        this.size = size;
    }

    /**
     * @return the offsets
     */
    public int[] getOffsets() {
        return offsets;
    }

    /**
     * @param offsets the offsets to set
     */
    public void setOffsets(int[] offsets) {
        this.offsets = offsets;
    }

    /**
     * @return the memoryModel
     */
    public MemoryModel getMemoryModel() {
        return memoryModel;
    }

    /**
     * @param memoryModel the memoryModel to set
     */
    public void setMemoryModel(MemoryModel memoryModel) {
        this.memoryModel = memoryModel;
    }
}
